package com.uraurora.crescent.advanced.tree.impl;

import com.uraurora.crescent.advanced.tree.ISuffixTree;
import com.uraurora.crescent.util.Trees;

import java.util.Arrays;

/**
 * @author : gaoxiaodong04
 * @program : crescent
 * @date : 2020-06-11 17:15
 * @description :
 */
public class SuffixTree implements ISuffixTree {

    private final Trie trie;

    public SuffixTree() {
        trie = Trees.newTrie();
    }

    @Override
    public void add(String str) {
        this.trie.append(toSuffixString(str));
    }

    @Override
    public void add(char[] chars) {
        this.trie.append(toSuffixString(String.valueOf(chars)));
    }

    public SuffixTree append(String[] strs){
        for (String str : strs){
            this.trie.add(str);
        }
        return this;
    }

    public SuffixTree append(Iterable<String> strs){
        for (String str : strs){
            this.trie.add(str);
        }
        return this;
    }

    @Override
    public boolean contains(String sub) {
        return false;
    }

    @Override
    public String[] toDictOrderArray() {
        return new String[0];
    }

    private static String[] toSuffixString(String str){
        int length = str.length();
        String[] res = new String[length];
        for (int i = 0; i < length; i++) {
            res[i] = str.substring(length - i - 1, length);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(toSuffixString("str")));
    }
}
